/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ile.VISTA;

import ile.DAO.DevolucionDAO;
import ile.DAO.DevolucionMDAO;
import ile.DAO.MarcaDAO;
import ile.DAO.MarcaMDAO;
import ile.DAO.PedidoDAO;
import ile.DAO.PedidoMaterialDAO;
import ile.ModeloTabla.ListadeDevolucionesMaterialModelTable;
import ile.ModeloTabla.ListadeDevolucionesModelTable;
import ile.Modelo.Devolucion;
import ile.Modelo.DevolucionMaterial;
import ile.Modelo.Marca;
import ile.Modelo.Marka;
import ile.Modelo.Pedido;
import ile.Modelo.PedidoMaterial;
import ile.Modelo.Usuario;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author 
 */
public class DevolucionesMateriales extends javax.swing.JDialog {
   List<DevolucionMaterial> devolucionMs;
    ListadeDevolucionesMaterialModelTable ldmmt;
    
    Usuario usuario;

    /**
     * Creates new form PedidoHerramientas
     */
    public DevolucionesMateriales(java.awt.Frame parent, boolean modal, Usuario u) {
        super(parent, modal);
        devolucionMs= new ArrayList<DevolucionMaterial>();
        ldmmt= new ListadeDevolucionesMaterialModelTable();
        initComponents();
        usuario=u;
        lblUsuario.setText(usuario.getNombre());
       // setMaximumSize(Integer.MAX_VALUE);
       //setSize(new DimensionUIResource(Integer.MAX_VALUE,Integer.MAX_VALUE));
   
        setLocationRelativeTo(null);
    }
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tablaDevMateriales = new javax.swing.JTable();
        btnElimnarPH = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tablaPedidosM = new javax.swing.JTable();
        jLabel3 = new javax.swing.JLabel();
        txtDevM = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        btnBuscarH = new javax.swing.JButton();
        btnOkH = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        btnCancelar = new javax.swing.JButton();
        btnAceptarH = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        lblUsuario = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(126, 166, 189));
        jPanel1.setAutoscrolls(true);

        jPanel2.setBackground(new java.awt.Color(126, 166, 189));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(java.awt.Color.white, 2, true), "Lista de Pedidos de Herramientas", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("DejaVu Serif", 1, 16))); // NOI18N

        tablaDevMateriales.setBackground(new java.awt.Color(225, 254, 210));
        tablaDevMateriales.setModel(ldmmt);
        jScrollPane2.setViewportView(tablaDevMateriales);

        btnElimnarPH.setFont(new java.awt.Font("DejaVu Serif", 1, 15)); // NOI18N
        btnElimnarPH.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Borrar.png"))); // NOI18N
        btnElimnarPH.setText("Eliminar");
        btnElimnarPH.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnElimnarPHActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 808, Short.MAX_VALUE)
                .addGap(15, 15, 15)
                .addComponent(btnElimnarPH, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(0, 11, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnElimnarPH, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(32, 32, 32))
        );

        jPanel4.setBackground(new java.awt.Color(126, 166, 189));
        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(java.awt.Color.white, 2, true), "Lista de Pedidos de Herramientas", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("DejaVu Serif", 1, 16))); // NOI18N

        tablaPedidosM.setBackground(new java.awt.Color(225, 254, 210));
        tablaPedidosM.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        tablaPedidosM.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        tablaPedidosM.setGridColor(new java.awt.Color(5, 5, 5));
        tablaPedidosM.setSelectionBackground(new java.awt.Color(151, 199, 234));
        jScrollPane3.setViewportView(tablaPedidosM);

        jLabel3.setFont(new java.awt.Font("DejaVu Serif", 1, 23)); // NOI18N
        jLabel3.setForeground(java.awt.Color.black);
        jLabel3.setText("Nombre:");

        txtDevM.setFont(new java.awt.Font("DejaVu Serif", 0, 22)); // NOI18N
        txtDevM.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtDevMMouseClicked(evt);
            }
        });
        txtDevM.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtDevMKeyTyped(evt);
            }
        });

        jPanel5.setBackground(java.awt.Color.lightGray);
        jPanel5.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 169, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 149, Short.MAX_VALUE)
        );

        btnBuscarH.setFont(new java.awt.Font("DejaVu Serif", 1, 15)); // NOI18N
        btnBuscarH.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/view.png"))); // NOI18N
        btnBuscarH.setText("Buscar");
        btnBuscarH.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarHActionPerformed(evt);
            }
        });

        btnOkH.setFont(new java.awt.Font("DejaVu Serif", 1, 15)); // NOI18N
        btnOkH.setText("Ok");
        btnOkH.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOkHActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("DejaVu Serif", 1, 20)); // NOI18N
        jLabel4.setText("Gráfica");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtDevM)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnBuscarH, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 806, Short.MAX_VALUE))
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel4Layout.createSequentialGroup()
                            .addGap(15, 15, 15)
                            .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(btnOkH, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(53, 53, 53)
                        .addComponent(jLabel4)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(txtDevM, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnBuscarH, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnOkH, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        btnCancelar.setFont(new java.awt.Font("DejaVu Serif", 1, 15)); // NOI18N
        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/cancelar.png"))); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        btnAceptarH.setFont(new java.awt.Font("DejaVu Serif", 1, 15)); // NOI18N
        btnAceptarH.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/ok.png"))); // NOI18N
        btnAceptarH.setText("Aceptar");
        btnAceptarH.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptarHActionPerformed(evt);
            }
        });

        jLabel1.setText("Usuario:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btnAceptarH, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 384, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addContainerGap()))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(lblUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 404, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btnAceptarH, javax.swing.GroupLayout.DEFAULT_SIZE, 65, Short.MAX_VALUE)
                    .addComponent(btnCancelar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(22, 22, 22)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(403, Short.MAX_VALUE)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtDevMMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtDevMMouseClicked
        // TODO add your handling code here:
        
       new TecladoVirtual(null, true, txtDevM, tablaPedidosM, "DevM").setVisible(true);
    }//GEN-LAST:event_txtDevMMouseClicked

    private void btnOkHActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkHActionPerformed
        // TODO add your handling code here:
        DefaultTableModel model= (DefaultTableModel) tablaPedidosM.getModel();
        for (int i = 0; i < model.getRowCount(); i++) {
            
            String cadena=String.valueOf(tablaPedidosM.getValueAt(i, 5));
            Boolean bandera= Boolean.valueOf(cadena);
            if(bandera==true){    
                PedidoMaterial pm= pedidoMs.get(i);
                DevolucionMaterial devolucionMaterial= new DevolucionMaterial();
                
                try {
                    
               
                String cantidad = String.valueOf(tablaPedidosM.getValueAt(i, 4));
                     int cant= Integer.valueOf(cantidad);
                     devolucionMaterial.setCantidadEntregada(cant);
                     
//                 int cantidadResta = pm.getCantidad() - cant;
//                tablaPedidosM.setValueAt(cantidadResta, i, 3);
//                pm.setCantidad(cantidadResta);
//             
//                     int cantDisponibleMarca=pm.getMarka().getDisponibleM()+cant;
//                        pm.getMarka().setDisponibleM(cantDisponibleMarca);
                     
                devolucionMaterial.setPedidoMaterial(pm);
                devolucionMs.add(devolucionMaterial);
                
                 } catch (Exception e) {
                   JOptionPane.showMessageDialog(null, "Existen Campos Vacíos");
                }
                  
            }else {
                String cad=String.valueOf(tablaPedidosM.getValueAt(i, 4));
                    if(bandera==false && !cad.equals("")){
                        JOptionPane.showMessageDialog(null, "Existen Campos Vacíos");
                        break;
            }

        }
        }
        ldmmt= (ListadeDevolucionesMaterialModelTable) tablaDevMateriales.getModel();
        ldmmt.setFilas(devolucionMs);
        for (int i = 0; i < tablaPedidosM.getRowCount(); i++) {
            tablaPedidosM.setValueAt("", i, 4);
            tablaPedidosM.setValueAt(false, i, 5);
            
        }
        
     // lpmt.setPedido(null);
    }//GEN-LAST:event_btnOkHActionPerformed

    private void btnElimnarPHActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnElimnarPHActionPerformed
        // TODO add your handling code here:
        ListadeDevolucionesMaterialModelTable table= (ListadeDevolucionesMaterialModelTable) tablaDevMateriales.getModel();
        DevolucionMaterial devolucionSeleccionada= table.getDevMaterial();
    
        List<DevolucionMaterial> listaDevolucions = table.getFilas();
        if (devolucionSeleccionada != null) {
            int rta = JOptionPane.showConfirmDialog(this, "Desea realmente eliminar la Devolucón? "
                    + devolucionSeleccionada.getPedidoMaterial().getMarka().getMaterial(), "Eliminar", JOptionPane.YES_NO_OPTION);

            if (rta == JOptionPane.YES_OPTION) {
                listaDevolucions.remove(devolucionSeleccionada);
                table.setFilas(listaDevolucions);
                JOptionPane.showMessageDialog(this, "Devolución eliminada", "Información", JOptionPane.INFORMATION_MESSAGE);

            }

        }else{
            JOptionPane.showMessageDialog(this, "No se ha realizado ninguna Devolución", "Error", JOptionPane.ERROR_MESSAGE);
        }
        
        table.setDevMaterial(null);
 
    }//GEN-LAST:event_btnElimnarPHActionPerformed

    private void btnBuscarHActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarHActionPerformed
        // TODO add your handling code here:
        cargarPedidosM();
    }//GEN-LAST:event_btnBuscarHActionPerformed

    private void txtDevMKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDevMKeyTyped
        // TODO add your handling code here:
        cargarPedidosM();
    }//GEN-LAST:event_txtDevMKeyTyped

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnAceptarHActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarHActionPerformed
        
        ListadeDevolucionesMaterialModelTable listadeDMMT= (ListadeDevolucionesMaterialModelTable) tablaDevMateriales.getModel();
        DevolucionMaterial devolucionSeleccionada= listadeDMMT.getDevMaterial();
        if(devolucionSeleccionada!= null){

          for (int i = 0; i < devolucionMs.size(); i++) {
           
                DevolucionMaterial dm= devolucionMs.get(i);
                PedidoMaterial pedidoM = dm.getPedidoMaterial();
                
                DevolucionMDAO devolucionMDAO= new DevolucionMDAO(dm);
                pedidoM.agregarDM(dm);
                PedidoMaterialDAO  pedidoMdAO= new PedidoMaterialDAO(pedidoM);
                Marka marka= pedidoM.getMarka();
                MarcaMDAO marcaMDAO= new MarcaMDAO(marka);
               
                try {
                devolucionMDAO.persist();
                pedidoMdAO.update();
                marcaMDAO.update();
            } catch (Exception ex) {
                Logger.getLogger(DevolucionesMateriales.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        JOptionPane.showMessageDialog(null, "Devolución receptada satisfactoriamente");
        dispose();
        }else{
           
           JOptionPane.showMessageDialog(this, "No ha realizado ninguna Devolución de Materiales", "Error", JOptionPane.ERROR_MESSAGE);
           dispose();
        }

    }//GEN-LAST:event_btnAceptarHActionPerformed

    List<PedidoMaterial> pedidoMs;
    public void cargarPedidosM(){
        PedidoMaterialDAO pmaterialDAO= new PedidoMaterialDAO(null);
       pedidoMs = pmaterialDAO.buscartodos();

        DefaultTableModel TableModel = new DefaultTableModel(){
            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                if(columnIndex==4 || columnIndex==5){
                return true;
                }else{
                return false;
                }

             }

            @Override
            public Class getColumnClass(int columna){
            if(columna==4){
            return Integer.class;
            }if(columna==5){
                return Boolean.class;
            }
            return Class.class;
    }

        };
        String []  columnaNombre={"Num OT", "Codigo","Material","Cant Entregada", "Cant Devolver", "Selección"};
        TableModel.setColumnIdentifiers(columnaNombre);
        Object[] fila=new Object[TableModel.getColumnCount()];
        for (int i = 0; i < pedidoMs.size(); i++) {
            fila[0] = pedidoMs.get(i).getOtm();
            fila[1] = pedidoMs.get(i).getMarka().getMaterial().getCodigo();
            fila[2] = pedidoMs.get(i).getMarka().getMaterial().getNombre();
            fila[3] = pedidoMs.get(i).getCantidad();
            fila[4] = "";

         TableModel.addRow(fila);
        }
      tablaPedidosM.setModel(TableModel);

        
    }
    
   
    /**
     * @param args the command line arguments
     */
 
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAceptarH;
    private javax.swing.JButton btnBuscarH;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnElimnarPH;
    private javax.swing.JButton btnOkH;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JLabel lblUsuario;
    private javax.swing.JTable tablaDevMateriales;
    private javax.swing.JTable tablaPedidosM;
    private javax.swing.JTextField txtDevM;
    // End of variables declaration//GEN-END:variables
}
